local joy__shixian = fk.CreateSkill {

  name = "joy__shixian",

  tags = { Skill.Compulsory, },

}



joy__shixian:addEffect(fk.TurnStart, {
  name = "joy__shixian",
  events = {fk.TurnStart},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, _, target, player, data)
    return player:hasSkill(joy__shixian.name) and target == player
  end,
  on_use = function(self, _, target, player, data)
    local room = player.room
    local names = {"joy__xiakexing", "joy__qiangjinjiu", "joy__jingyesi", "joy__xinglunan"}
    room:handleAddLoseSkills(player, "-"..table.concat(names, "|-"))
    local cards = room:getNCards(4)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonPut, joy__shixian.name)
    room:delay(1000)
    local map = {}
    for _, id in ipairs(cards) do
      local suit = Fk:getCardById(id).suit
      map[suit] = map[suit] or {}
      table.insert(map[suit], id)
    end
    local get = {}
    for suit, ids in pairs(map) do
      room:handleAddLoseSkills(player, names[suit])
      if #ids > 1 then
        table.insertTable(get, ids)
      end
    end
    if #get > 0 and not player.dead then
      room:moveCardTo(get, Card.PlayerHand, player, fk.ReasonPrey, joy__shixian.name)
    end
    cards = table.filter(cards, function(id) return Fk:getCardById(id) == Card.Processing end)
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
      })
    end
  end,
})

return joy__shixian